<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>楼层资源管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
        var imgflag=true;
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					
					 var table = document.getElementById("floornodeList");
	                    var rows = table.rows.length ;
	                    if(rows!=0){
                            $("#floornodeList tr").each(function(){
                                    imgflag=true;
                                    var reg = /\d+/g;
                                    var str = this.id;
                                    var i = str.match(reg)
                                    var floorimage = $("#floornodes"+i+"_floorimg").val();
                                    if(document.getElementById("floornodeList"+i).className!="error") {
                                        if(floorimage == null || floorimage == "") {
                                            alertx("<spring:message code='tip.pleasechooseimg'/>")
                                            imgflag = false;
                                            return false;
                                        }
									}
                            }
                            )
	                    }
                            if(imgflag){
                                loading('<spring:message code="common.subbmiting"/>');
                                timeVali($("#btnSubmit"));
                                form.submit();
                            }
	                       /* for (var i=0;i<rows;i++)
	                        {
	                           var floorimage = $("#floornodes"+i+"_floorimg").val();

	                            if(floorimage == null || floorimage == "") {
	                                alertx("<spring:message code='tip.pleasechooseimg'/>")
	                                return false;
								}
	                        }*/
                           // loading('<spring:message code="common.subbmiting"/>');
                            //timeVali($("#btnSubmit"));
                           // form.submit();

				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		function addRow(list, idx, tpl, row){
			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
				var ss = $(this).attr("data-value").split(',');
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
		}
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().parent().remove();
			}else if(delFlag.val() == "0"){
				delFlag.val("1");
				$(obj).html("&divide;").attr("title", "撤销删除");
				$(obj).parent().parent().addClass("error");
                $(obj).parent().parent().css("display","none");
			}else if(delFlag.val() == "1"){
				delFlag.val("0");
				$(obj).html("&times;").attr("title", "<spring:message code='common.delete'/>");
				$(obj).parent().parent().removeClass("error");
			}
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/source/floor/eleSourceFloor/"><spring:message code="floor.list"/></a></li>
		<li class="active"><a href="${ctx}/source/floor/eleSourceFloor/form?id=${eleSourceFloor.id}">
		<shiro:hasPermission name="source:floor:eleSourceFloor:edit">
			<c:if test="${not empty eleSourceFloor.id}">
					<spring:message code="floor.modify"/>
				</c:if>
				<c:if test="${empty eleSourceFloor.id}">
					<spring:message code="floor.add"/>
				</c:if>
	
		</shiro:hasPermission>
		<shiro:lacksPermission name="source:floor:eleSourceFloor:edit"><spring:message code="floor.info"/>
		</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="eleSourceFloor" action="${ctx}/source/floor/eleSourceFloor/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label"><spring:message code="common.dname"/>：</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="50" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<c:if test="${language == 'zh'}">
		<%--<div class="control-group">
			<label class="control-label"><spring:message code="floor.image"/>：</label>
			<div class="controls">
				<form:radiobuttons path="image2floor" items="${fns:getDictList('truefalse')}" itemLabel="label" itemValue="value" htmlEscape="false" class=""/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><spring:message code="floor.text"/>：</label>
			<div class="controls">
				<form:radiobuttons path="sub2floor" items="${fns:getDictList('truefalse')}" itemLabel="label" itemValue="value" htmlEscape="false" class=""/>
			</div>
		</div>--%>
		<div class="control-group">
			<label class="control-label"><spring:message code="floor.align"/>：</label>
			<div class="controls">
				<form:select path="alignment" >
					<form:options items="${fns:getDictList('textalign')}" itemLabel="label" itemValue="value" htmlEscape="false" class="input-small"/>
				</form:select>
			</div>
		</div>
		</c:if>
		<c:if test="${language == 'en'}">
	<%--	<div class="control-group">
			<label class="control-label"><spring:message code="floor.image"/>：</label>
			<div class="controls">
				<form:radiobuttons path="image2floor" items="${fns:getDictList('truefalse')}" itemLabel="enlabel" itemValue="value" htmlEscape="false" class=""/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><spring:message code="floor.text"/>：</label>
			<div class="controls">
				<form:radiobuttons path="sub2floor" items="${fns:getDictList('truefalse')}" itemLabel="enlabel" itemValue="value" htmlEscape="false" class=""/>
			</div>
		</div>--%>
		<div class="control-group">
			<label class="control-label"><spring:message code="floor.align"/>：</label>
			<div class="controls">
				<form:select path="alignment" >
					<form:options items="${fns:getDictList('textalign')}" itemLabel="enlabel" itemValue="value" htmlEscape="false" class="input-small"/>
				</form:select>			
				</div>
		</div>
		</c:if>
		<div class="control-group">
			<label class="control-label"><spring:message code='common.remarks'/>：</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="255" class="input-xlarge "/>
			</div>
		</div>
			<div class="control-group">
				<label class="control-label"><spring:message code="floor"/>：</label>
				<div class="controls">
					<table id="contentTable" class="table table-striped table-bordered table-condensed" >
						<thead>
							<tr>
								<th class="hide"></th>
								<th><spring:message code="floor.ph"/></th>
								<th><spring:message code="floor.voice.chinese"/></th>
								<th><spring:message code="floor.voice.english"/></th>
								<th><spring:message code="floor.display"/></th>
								<shiro:hasPermission name="source:floor:eleSourceFloor:edit"><th width="10">&nbsp;</th></shiro:hasPermission>
							</tr>
						</thead>
						<tbody id="floorList">
						</tbody>
						<shiro:hasPermission name="source:floor:eleSourceFloor:edit"><tfoot>
							<tr  style="background-color:#fdfdfd;"><td colspan="7"><a href="javascript:" onclick="addRow('#floorList', floorRowIdx, floorTpl);floorRowIdx = floorRowIdx + 1;" class="btn"><spring:message code="common.add"/></a></td></tr>
						</tfoot></shiro:hasPermission>
					</table>
					<script type="text/template" id="floorTpl">//<!--
						<tr id="floors{{idx}}">
							<td class="hide">
								<input id="floors{{idx}}_id" name="floors[{{idx}}].id" type="hidden" value="{{row.id}}"/>
								<input id="floors{{idx}}_delFlag" name="floors[{{idx}}].delFlag" type="hidden" value="0"/>
							</td>
							<td>
								<input id="floors{{idx}}_floorId" name="floors[{{idx}}].floorId" type="text" value="{{row.floorId}}" maxlength="11" class="input-small required"  regexp="^[A-Za-z0-9]+$"/>
							</td>
							<td>
								<input id="floors{{idx}}_volumeCn" name="floors[{{idx}}].volumeCn" type="hidden" value="{{row.volumeCn}}" maxlength="255"/>
								<sys:ckfinder input="floors{{idx}}_volumeCn" type="audios" uploadPath="/source/floor/eleSourceFloor" selectMultiple="false"/>
							</td>
							<td>
								<input id="floors{{idx}}_volumeEn" name="floors[{{idx}}].volumeEn" type="hidden" value="{{row.volumeEn}}" maxlength="255"/>
								<sys:ckfinder input="floors{{idx}}_volumeEn" type="audios" uploadPath="/source/floor/eleSourceFloor" selectMultiple="false"/>
							</td>
							<td>
								<input id="floors{{idx}}_toFloor" name="floors[{{idx}}].toFloor" type="text" value="{{row.toFloor}}" maxlength="255" class="input-small "/>
							</td>
							<shiro:hasPermission name="source:floor:eleSourceFloor:edit"><td class="text-center" width="10">
								{{#delBtn}}<span class="close" onclick="delRow(this, '#floors{{idx}}')" title="<spring:message code='common.delete'/>">&times;</span>{{/delBtn}}
							</td></shiro:hasPermission>
						</tr>//-->
					</script>
					<script type="text/javascript">
						var floorRowIdx = 0, floorTpl = $("#floorTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
						$(document).ready(function() {
							var data = ${fns:toJson(eleSourceFloor.floors)};
							for (var i=0; i<data.length; i++){
								addRow('#floorList', floorRowIdx, floorTpl, data[i]);
								floorRowIdx = floorRowIdx + 1;
							}
						});
					</script>
				</div>
			</div>
			
			<div class="control-group">
				<label class="control-label"><spring:message code="floor.node"/>：</label>
				<div class="controls">
					<table id="contentTable" class="table table-striped table-bordered table-condensed" >
						<thead>
							<tr>
								<th class="hide"></th>
								<th><spring:message code="floor.number"/></th>
								<th><spring:message code="floor.picture"/></th>
								
								<shiro:hasPermission name="source:floor:eleSourceFloor:edit"><th width="10">&nbsp;</th></shiro:hasPermission>
							</tr>
						</thead>
						<tbody id="floornodeList">
						</tbody>
						<shiro:hasPermission name="source:floor:eleSourceFloor:edit"><tfoot>
							<tr style="background-color:#fdfdfd;"><td colspan="3"><a href="javascript:" onclick="addRow('#floornodeList', floorNodeRowIdx, floorNodeTpl);floorNodeRowIdx = floorNodeRowIdx + 1;" class="btn"><spring:message code="common.add"/></a></td></tr>
						</tfoot></shiro:hasPermission>
					</table>
					<script type="text/template" id="floorNodeTpl">//<!--
						<tr id="floornodes{{idx}}">
							<td class="hide">
								<input id="floornodes{{idx}}_id" name="floornodes[{{idx}}].id" type="hidden" value="{{row.id}}"/>
								<input id="floornodes{{idx}}_delFlag" name="floornodes[{{idx}}].delFlag" type="hidden" value="0"/>
							</td>
							<td>
								<input id="floornodes{{idx}}_floorId" name="floornodes[{{idx}}].floorId" type="text" value="{{row.floorId}}" maxlength="11" class="input-small required"/>
							</td>
							<td>
								<input id="floornodes{{idx}}_floorimg" name="floornodes[{{idx}}].floorimg" type="hidden" value="{{row.floorimg}}" maxlength="255"/>
								<sys:ckfinder input="floornodes{{idx}}_floorimg" type="images" uploadPath="/source/floor/eleSourceFloorNode" selectMultiple="false"/>
							</td>
							<shiro:hasPermission name="source:floor:eleSourceFloor:edit"><td class="text-center" width="10">
								{{#delBtn}}<span class="close" onclick="delRow(this, '#floornodes{{idx}}')" title="<spring:message code='common.delete'/>">&times;</span>{{/delBtn}}
							</td></shiro:hasPermission>
						</tr>//-->
					</script>
					<script type="text/javascript">
						var floorNodeRowIdx = 0, floorNodeTpl = $("#floorNodeTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
						$(document).ready(function() {
							var data = ${fns:toJson(eleSourceFloor.floornodes)};
							for (var i=0; i<data.length; i++){
								addRow('#floornodeList', floorNodeRowIdx, floorNodeTpl, data[i]);
								floorNodeRowIdx = floorNodeRowIdx + 1;
							}
						});
					</script>
				</div>
			</div>
			
		<div class="form-actions">
			<shiro:hasPermission name="source:floor:eleSourceFloor:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="<spring:message code='common.save'/>"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="<spring:message code='common.back'/>" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>